<template>
  <div class="logBox worksheetRecordLog">
    <a-spin :spinning="spinning">
      <eip-empty v-if="dataLog.length == 0" />
      <div
        class="worksheetRocordLogCard"
        v-for="(item, index) in dataLog"
        :key="index"
      >
        <div class="worksheetRocordLogCardTopBox">
          <div class="worksheetRocordLogCardTitle flex">
            <span class="selectTriggerChildAvatar"
              ><span
                class="avatarBox worksheetRocordLogCardTitleAvatar"
                style="width: 20px; height: 20px"
              ></span
              ><span class="titleAvatarText accountName"
                ><img
                  :src="item.createUserHeadImage"
                  style="
                    width: 20px;
                    height: 20px;
                    border-radius: 50%;
                    margin-right: 2px;
                  "
                />{{ item.createUserName }}</span
              ></span
            ><span
              ><span class="Gray_9e">
                <span class="mLeft2" v-if="item.type == 2"
                  >更新{{ item.contentJson.length }}个字段</span
                >
                <span class="mLeft2" v-if="item.type == 1"
                  >创建了记录</span
                ></span
              ></span
            >
          </div>
          <div class="worksheetRocordLogCardName nowrap Gray_9e mLeft12">
            {{ item.createTime }}
          </div>
        </div>
        <div class="worksheetRocordLogCardHrCon">
          <div
            class="worksheet-rocord-log-item"
            v-for="(contentItem, contentIndex) in item.contentJson"
            :key="contentIndex"
          >
            <div class="widgetTitle">
              <span class="selectTriggerChild hasHover"
                ><span>{{ contentItem.Name }}</span></span
              ><span class="extendText"></span>
            </div>
            <div class="WorksheetRocordLogSelectTags paddingLeft27">
              <span
                class="WorksheetRocordLogSelectTag oldValue"
                v-if="contentItem.Before"
              >
                {{ contentItem.Before }}</span
              ><span
                class="WorksheetRocordLogSelectTag newValue"
                v-if="contentItem.After"
              >
                {{ contentItem.After }}</span
              >
            </div>
          </div>
        </div>
      </div>
    </a-spin>
  </div>
</template>

<script>
import { agileDataLogRelationId } from "@/services/system/zerocode/run/edit";
export default {
  components: {},
  name: "dataLog",
  computed: {},
  data() {
    return {
      dataLog: [],
      spinning: true,
    };
  },

  props: {
    rowId: {
      type: String,
    },
  },
  watch: {
    //若有改变则赋予属性
    rowId(val) {
      if (val) {
        this.agileLogData();
      }
    },
  },
  mounted() {
    this.agileLogData();
  },
  methods: {
    /**
     * 获取敏捷开发日志
     */
    agileLogData() {
      let that = this;
      agileDataLogRelationId({
        rowId: this.rowId,
      }).then((result) => {
        if (result.code == that.eipResultCode.success) {
          result.data.forEach((item) => {
            item.contentJson =
              item.type == 2
                ? JSON.parse(item.content).filter((f) => !f.Hidden)
                : [];
          });
          that.dataLog = result.data;

          that.$emit("initOk", result.data);
          that.spinning = false;
        }
      });
    },
  },
};
</script>

<style lang="less">
.logBox {
  box-sizing: border-box;
  padding: 6px 10px 0;
  padding-left: 10px !important;
}

.logBox .paddingLeft27 {
  padding-left: 7px;
}

.logBox .moreLogData {
  cursor: pointer;
  margin-left: 28px;
}

.logBox .selectTriggerChildAvatar .accountName {
  border-radius: 5px;
  cursor: pointer;
  padding: 3px 5px;
}

.logBox .selectTriggerChildAvatar .accountName:hover {
  background: #f7f7f7;
  color: #2196f3;
}

.logBox .selectTriggerChildAvatar .accountName.mobileAccountName:hover {
  background: #fff;
  color: #9e9e9e;
}

.logBox .selectTriggerChild {
  align-items: center;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  padding: 3px 5px;
}

.logBox .selectTriggerChild.hasHover:hover {
  background: #f7f7f7;
  color: #2196f3;
}

.logBox .selectTriggerChild.hasHover:hover .icon {
  color: #2196f3 !important;
}

.logBox .worksheetRocordLogCard {
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  margin-bottom: 16px;
  padding: 16px;
}

.logBox .worksheetRocordLogCard .worksheetRocordLogCardTopBox {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.logBox .worksheetRocordLogCard .worksheetRocordLogCardTopBox span {
  line-height: 20px;
}

.logBox
  .worksheetRocordLogCard
  .worksheetRocordLogCardTopBox
  .worksheetRocordLogCardTitleAvatar {
  height: auto !important;
  margin-right: 2px;
}

.logBox
  .worksheetRocordLogCard
  .worksheetRocordLogCardTopBox
  .worksheetRocordLogCardTitleAvatar
  img {
  margin-top: -4px;
}

.logBox
  .worksheetRocordLogCard
  .worksheetRocordLogCardTopBox
  .titleAvatarText
  a {
  color: #333;
}

.logBox
  .worksheetRocordLogCard
  .worksheetRocordLogCardTopBox
  .titleAvatarText
  a:hover {
  color: #40a9ff;
}

.logBox .worksheetRocordLogCard .worksheetRocordLogCardHrTime {
  border-top: 1px solid #eaeaea;
  color: #9e9e9e;
  display: flex;
  justify-content: space-between;
  margin-left: 7px;
  margin-top: 16px;
  padding-top: 16px;
}

.logBox .worksheetRocordLogCard:last-child .worksheetRocordLogCardTopBox {
  margin-bottom: 0;
}

.logBox .loadOldLog {
  color: #9e9e9e;
  font-size: 12px;
  margin: 16px 0;
  text-align: center;
}

.logBox .loadOldLog span:hover {
  cursor: pointer;
  font-size: #1890ff;
}

.logBox .logDivider {
  color: #9e9e9e;
  font-size: 12px;
}

.logBox .worksheet-rocord-log-item {
  margin-top: 4px;
}

.logBox .worksheet-rocord-log-item .widgetTitle {
  align-items: center;
  display: flex;
  font-size: 13px;
  margin-left: 2px;
  margin-right: 8px;
}

.logBox .worksheet-rocord-log-item .widgetTitle > span:first-child {
  font-weight: 700;
}

.logBox .worksheet-rocord-log-item .widgetTitle .icon {
  display: inline-block;
  vertical-align: middle;
  width: 20px;
}

.logBox .hideEle {
  display: none;
}

.logBox.mobileLogBox {
  font-size: 13px;
  padding: 10px 10px 0 !important;
}

.logBox.mobileLogBox .worksheetRocordLogCardTopBox {
  font-size: 12px;
}

.logBox.mobileLogBox .worksheet-rocord-log-item {
  padding: 0;
  text-align: justify;
}

.worksheetRocordLog {
  background: #fafafa;
}

.worksheetRecordLog .oldBackground {
  background: #feeaec;
  text-decoration: line-through;
}

.worksheetRecordLog .newBackground {
  background: #dff8ea;
}

.worksheetRecordLog .defaultBackground {
  background: #f0f0f0;
}

.WorksheetRocordLogSelectTags {
  display: flex;
  flex-wrap: wrap;
  justify-content: left;
}

.WorksheetRocordLogSelectTags .WorksheetRocordLogSelectTag {
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  word-wrap: break-word;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  height: auto;
  line-height: 20px;
  margin-bottom: 4px;
  margin-right: 4px;
  overflow: hidden;
  padding: 0 8px;
  text-overflow: ellipsis;
  width: fit-content;
}

.WorksheetRocordLogSelectTags .hoverHighline {
  cursor: pointer;
}

.WorksheetRocordLogSelectTags .hoverHighline:hover {
  color: #0d47a1;
}

.WorksheetRocordLogSelectTags .noneTextLineThrough {
  text-decoration: none !important;
}

.worksheetRecordLog .flexDirectionRever {
  flex-direction: row-reverse;
}

.worksheetRecordLog .oldValue {
  background: #feeaec;
  text-decoration: line-through;
}

.worksheetRecordLog .newValue {
  background: #dff8ea;
}

.worksheetRecordLog .defaultValue {
  background: rgba(0, 0, 0, 0.06);
}

.logBox .worksheetRocordLogCard:last-child {
  margin-bottom: 0 !important;
}
</style>
